/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.easoft.code.pos.ui;

import com.easoft.code.pos.App;
import com.easoft.code.pos.ui.beans.FormSeguridad;
import com.easoft.code.pos.ui.controls.ButtonMenu;
import com.easoft.code.pos.ui.leftoptions.ComponentBuilder;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Eliu
 */
public class FormPrincipal extends javax.swing.JFrame {

    /**
     * Creates new form FormPrincipal
     */
    public FormPrincipal() {
        initComponents();

        FormSeguridad s = new FormSeguridad(FormPrincipal.this, true);

        if (s.isDatosValidos()) {
            App.currentUser = s.getUsuario();
            configureLeftMenu();
        } else {
            System.exit(3);
        }

    }

    private String getOptionsUser() {
        switch (App.currentUser.getTipo()) {
            case 1:
                return "POSLauncherImpl";
            default:
                return "GeneralMaintenancesImpl,POSLauncherImpl,"
                        + "ConfiguracionesMaintenancesImpl,OperacionesInvImpl,ReportesBuilderImpl";
        }
    }

    private void configureLeftMenu() {
        String leftOptions = getOptionsUser();
        for (String o : leftOptions.split(",")) {
            try {
                Class c = Class.forName("com.easoft.code.pos.ui.leftoptions.impl." + o);
                ComponentBuilder b = (ComponentBuilder) c.newInstance();
                ButtonMenu m = new ButtonMenu(b.getName(), "leftmenu-option.png",
                        centerPanel, b);
                leftPanel.add(m);
            } catch (InstantiationException | IllegalAccessException | ClassNotFoundException ex) {
                Logger.getLogger(FormPrincipal.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        leftPanel = new javax.swing.JPanel();
        centerPanel = new javax.swing.JPanel();
        statusBar = new javax.swing.JPanel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu2 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Sistema Ventas Terceros");

        leftPanel.setLayout(new java.awt.GridLayout(7, 1));
        getContentPane().add(leftPanel, java.awt.BorderLayout.WEST);

        centerPanel.setLayout(new java.awt.GridLayout(1, 1));
        getContentPane().add(centerPanel, java.awt.BorderLayout.CENTER);
        getContentPane().add(statusBar, java.awt.BorderLayout.SOUTH);

        jMenu2.setText("Ayuda");
        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        pack();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel centerPanel;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel leftPanel;
    private javax.swing.JPanel statusBar;
    // End of variables declaration//GEN-END:variables
}
